package Control;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import Entity.MsgPackage;
import GUI.ExaminationStage_GUI;
import GUI.ScreenManager;
/**
 * Controls the instance of Examination Stage Control
 * This class sends and gets data from the server 
 * and display it on the panel.
 * @author Aviat
 *
 */ 
public class ExaminationStageControl {
	private ExaminationStage_GUI exam_stage_gui;
	private MsgPackage exam;
	private String[] data;
	private Boolean result;
	
	
	/**
	 * the constructor
	 */
	public ExaminationStageControl(){
		exam_stage_gui=new ExaminationStage_GUI();
		exam= new MsgPackage();
		data= new String [2];
		
	}

	/**
	 * 
	 * @return ExaminationStageGui
	 */
	public ExaminationStage_GUI getExaminationGui() {
		 return exam_stage_gui ;
	}
	
	/**
	 * 
	 * @param ReqNum to set the request number
	 */
	public void reqANDstageEntered(String ReqNum){
		data[0]=ReqNum;
	}
	
	/**
	 * This method sends the examiner decision to the server
	 *  The server sends an answer (received from query from database) 
	 *  and the control display it in a message
	 */	
		public boolean examination_Submit_pressed(Integer req_ID) {
			String x= (String)exam_stage_gui.getDecision().getSelectedItem();
			if(x==null){
				JOptionPane.showMessageDialog(null, "you have to choose one option ", "ERROR", JOptionPane.ERROR_MESSAGE);
				return false;
			}
			else{
				data[0] = req_ID.toString();
				data[1]=(String)exam_stage_gui.getDecision().getSelectedItem();
				exam.setObject(data);
				exam.setOp_code(OP_CODE.SET_EXAMINATION_STAGE);
				ScreenManager.getConnection().accept(exam);
				
				//while(ScreenManager.getConnection().getAnswerReceivedFlag() == false);	//wait until flag is changed and shows that result was received from server
		    	//Object o = ScreenManager.getConnection().getResultobject();
				Object o = ScreenManager.getConnection().cclient.getMessage();
				result = (Boolean)o;
				JOptionPane.showMessageDialog(null, "Your stage was updated successfully!!", "", JOptionPane.INFORMATION_MESSAGE);
				return true;
			}

	
	}

	
}
